{include file="public/header" /}


    
<div class="x-body">
  <div class="layui-row">
    <form class="layui-form layui-col-md12 x-so" action="__APP__/admin/Adminuser/index" method="get">

      <input type="text" name="username_s" id="username_s" placeholder="账号" autocomplete="off" class="layui-input">
      <input type="text" name="phone_s" id="phone_s" placeholder="手机号" autocomplete="off" class="layui-input">
      <div class="layui-input-inline">
        <select name="groupid_s" id="groupid_s">
          <option value=''>角色筛选</option>
          {foreach name="admingroup_list" item="v" key="k" }
            <option value="{$v.id}">{$v.groupname}</option>
          {/foreach}
        </select>
      </div>
      <button class="layui-btn"  type="submit"><i class="layui-icon">&#xe615;</i></button>
      
    </form>
    <script type="text/javascript">
      
        $("#phone_s").val("{$phone_s}");
        $("#groupid_s").val("{$groupid_s}");
        $("#username_s").val("{$username_s}");
    </script>

  </div>


  <xblock>
    
    <button class="layui-btn layui-btn-sm" onclick="model_add_edit(1)"><i class="layui-icon"></i>添加</button>
    
  </xblock>
  <table class="layui-table">
    <thead>
      <tr>
        <th>
          <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
        </th>
        <th>ID</th>
        <th>角色</th>
        <th>账号</th>
        <th>姓名</th>
        <th>手机</th>
        <!-- <th>邮箱</th> -->
        
        <th>最后登录时间</th>
        <th>状态</th>
        <th>操作</th>
    </thead>
    <tbody>
      {foreach name="lists" item="v" key="k" }
        <tr>
          <td>
            <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i class="layui-icon">&#xe605;</i></div>
          </td>
          <td>{$v.id}</td>
          <td>{$v.groupname}</td>
          <td>{$v.username}</td>
          <td>{$v.name}</td>
          <td>{$v.phone}</td>
          <!-- <td>{$v.email}</td> -->
          
          <td>{$v.lastlogin}</td>
          <td class="td-status">
            {if condition=" $v.status == '1' "}
            <span class="layui-badge-dot layui-bg-green"></span>
            <span class="layui-badge-rim">启用</span>
            {else if condition=" $v.status == '2' " /}
            <span class="layui-badge-dot"></span>
            <span class="layui-badge-rim">冻结</span>
      

            {/if}
          </td>
          <td class="td-manage">
            
            <a title="编辑"  onclick="model_add_edit(2,'{$v.id}','{$v.groupid}','{$v.username}','{$v.name}','{$v.phone}','{$v.status}')" class="layui-btn layui-btn-normal layui-btn-xs">编辑</a>
            <a title="删除" onclick="del({$v.id})" class="layui-btn layui-btn-danger layui-btn-xs">删除</a>

          </td>
        </tr>
      {/foreach}
    </tbody>
  </table>
  <div class="page">
    <div>
    {$page}
    </div>
  </div>

</div>



<!-- --------------------js--------------------- -->

<script>
//日期选择
layui.use('laydate', function(){
  var laydate = layui.laydate;
  
  //执行一个laydate实例
  laydate.render({
    elem: '#start' //指定元素
  });

  //执行一个laydate实例
  laydate.render({
    elem: '#end' //指定元素
  });
});


  //模态窗
  function model_add_edit (type,id,groupid,username,name,phone,status) {
    if(type == 1){
      var txt = '添加'; 
    }else{
      var txt = '编辑'; 

    }
    layui.use(['layer','form'], function() {
      var form = layui.form;    //渲染
      var layer = layui.layer; //唤起模态窗

      layer.open({
        type: 1,
        title: txt,
        area: ['400px'] ,
        shadeClose: true,
        content: $('#box').html()
      })
      $('#id').val(id);
      $('#name').val(name);
      $('#groupid').val(groupid);
      $('#username').val(username);
      $('#phone').val(phone);
      $(":radio[name='status'][value="+status+"]").attr("checked","checked");  
      if(type==2){
        $('#psw').hide();
      }
      form.render();//渲染
    })
  }


//确定-提交
function sub(){

  var groupid = $('#groupid').val();
  var username = $('#username').val();
  // var password = $('#password').val();
  var name = $('#name').val();
  var phone = $('#phone').val();

  if(groupid == '' || username == '' || name == '' || phone == ''){
      layer.msg('信息不完整',{
        time:900  ,           //时间
      });
      return false;
  }
  
  $.ajax({
      type:"get",
      url:"__APP__/admin/Adminuser/add_edit",
      data:$(".lay_box").serialize(),

      success:function(data){
        // alert(data);
        returnInfo(data);

      }        
  })//ajax结束
}

//删除
function del(id){
  layui.use('layer', function(){
    var layer = layui.layer;
    layer.open({
      title: '询问框'
      ,content: '确定删除这个管理员吗？'
      ,offset: '100px'   
      ,yes: function(index, layer){
          $.ajax({
            type:"post",
            url:"__APP__/admin/Adminuser/del",
            data:'id='+id,
            dataType:"json",//服务器返回类型
            success:function(data){
                // alert(data);
                 returnInfo(data);
            }
          })
      }
    })
  }); 
}

</script>


{include file="public/footer" /}


<!-- --------------------弹窗--------------------- -->

<script id="box">
        <style type="text/css">
          .layui-word-aux{
            font-size:12px;
          }
        </style>
        <form class="layui-form lay_box">
          <!-- -->
          <input type="hidden" id="id" name="id" value='' class="layui-input">
          <!-- -->
          <div class="layui-form-item" style="margin-top:20px">
              <label for="L_repass" class="layui-form-label">
                  <span class="x-red">*</span>选择角色
              </label>
              <div class="layui-input-inline">
                <select name="groupid" id="groupid" lay-verify="required">
                  <option value=""></option>
                  {foreach name="admingroup_list" item="v" key="k" }
                  <option value="{$v.id}">{$v.groupname}</option>
                  {/foreach}
                
                </select>
              </div>
       
          </div>
          <!-- -->
          <div class="layui-form-item" >
              <label for="username" class="layui-form-label">
                  <span class="x-red">*</span> 账号
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="username" name="username"  class="layui-input">
              </div>
          </div>
          <!-- -->
          <div class="layui-form-item" id="psw">
              <label class="layui-form-label">
                  <span class="x-red">*</span> 密码
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="password" name="password"  class="layui-input">
              </div>
          </div>
          <!-- -->
          <div class="layui-form-item">
              <label for="L_email" class="layui-form-label">
                  <span class="x-red">*</span> 姓名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="name" name="name" class="layui-input">
              </div>
          </div>
          <!-- -->
          <div class="layui-form-item">
              <label class="layui-form-label">
                <span class="x-red">*</span> 手机 
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="phone" name="phone"  class="layui-input" >
              </div>
          </div>
          <!-- -->
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
                <span class="x-red">*</span> 状态
              </label>
              
              <div class="layui-input-block">
                <input type="radio" name="status" id='status' value="1" title="启用" checked="">
                <input type="radio" name="status" id='status' value="2" title="冻结">
                
              </div>
          </div>

          <hr/>
          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>

              <a  class="layui-btn" onclick="sub()">
                  提交
              </a>
          </div>
      </form>
</script>